<style scoped>
  .weui-form-preview {
    background-color: #fff;
    margin: 5px;
    border-radius: 5px;
  }
  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }
  .rj-cell {
    display: inline-block;
    font-size: 0;
    padding: 5px 15px;
  }
  .rj-cell.max span{
    font-size: 16px;
    padding-right: 20px;
  }
  .rj-cell label {
    color: #333;
    font-size: 14px;
  }
  .rj-cell span {
    padding-left: 5px;
    font-size: 14px;
    color: #333;
  }
  .rj-cell.note label{
    float: left;
  }
  .rj-cell.note span{
    width: 80%;
    display: inline-block;
  }
  .weui-panel {
    background: #eee;
  }
  .rj-cont-tit {
    margin: 0;
    border-radius: 0;
  }
  .weui-panel {
    margin-top: 0;
    text-align: left;
  }
  .attachimg {
    /*width: 100%;*/
  }
  .tit label, .tit span {
    font-size: 16px;
  }
  .tit label {
    padding-right: 20px;
  }
  .weui-panel.weui-panel_access {
    padding-bottom: 10px;
  }
  .weui-panel__bd:not(.base) {
    width: 98%;
    padding: 0 1% 2px 1%;
  }
  .rj-cont-tit:not(.base) {
    border-radius: 5px;
  }
</style>
<template>
  <div class="viewapplystr">
    <div style="height: 50px; line-height: 50px; background: #f7f7f7; text-align: center; font-size: 16px; border-bottom: 1px solid #bdbbbc; position: relative">
      入库单详情
      <a href="javascript:;" @click="$router.back(-1)" style="position: absolute; left: 10px; top: 8px">
        <img src="@/assets/back.png" style="width: 20px" />
      </a>
    </div>
    <div class="weui-panel weui-panel_access">
      <div class="weui-panel__bd base">
        <div class="weui-form-preview billitem rj-cont-tit base">
          <div class="rj-cell max">
            <label>入库单编号：</label>
            <span>{{whinapply.code}}</span>
          </div>

          <div class="rj-cell max">
            <label>领料单编号：</label>
            <span>{{whinapply.pickinglistCode}}</span>
          </div>
          <div class="rj-cell max">
            <label>生产计划编号：</label>
            <span>{{whinapply.produceplanCode}}</span>
          </div>
          <div class="rj-cell max">
            <label>所在班组：</label>
            <span>{{whinapply.department}}</span>
          </div>
          <div class="rj-cell max">
            <label>领料类别：</label>
            <span>{{whinapply.pickType == 1 ? '生产领料' : '二次加工'}}</span>
          </div>
          <div class="rj-cell max">
            <label>下单日期：</label>
            <span>{{whinapply.createtime}}</span>
          </div>
          <div class="rj-cell max">
            <label>出库库房：</label>
            <span>{{whinapply.strname}}</span>
          </div>
          <div class="rj-cell max">
            <label>库存组织：</label>
            <span>{{whinapply.orgname}}</span>
          </div>
          <div class="rj-cell max">
            <label>状态：</label>
            <span>{{whinapply.statusName}}</span>
          </div>

          <div class="rj-cell ">
            <label>提交人：</label>
            <span>{{whinapply.operator}}</span>
          </div>
        </div>
      </div>
      <div class="weui-panel__hd" >入库单明细</div>
      <div class="weui-panel__bd" >
        <div class="weui-form-preview billitem rj-cont-tit">
          <div  style="border-top: 1px solid #eee;">
            <div  v-for="(item, index) in whinapply.items" :key="item.guid">
              <div class="rj-cell max">
                <label><span style="font-size: 14px;padding: 0;">产品：</span></label>
                <span>{{item.product}}</span>
                <span>{{item.spename}}</span>
                <span  v-show="item.weight != 0 ">{{item.weight}} {{item.stockunit}}</span>

              </div>
              <div class="rj-cell " v-show="item.housename != '' ">
                <label><span style="font-size: 14px;padding: 0;">库房：</span></label>
                <span>{{item.housename}}</span>
              </div>

            </div>
            <div class="weui-media-box weui-media-box_text uploaderFiles" v-if="whiFormImg != undefined && whiFormImg.length > 0">
              <p class="exp" style="font-size: 12px;color: #999;padding: 5px 0;">入库单照片</p>
              <div class="exp uploaderFiles" style="display: inline-block;">
                <img class="attachimg" style="padding-right: 5px;"  v-for="(image, index) in whiFormImg" :key="image.guid"  alt="" onerror="javascript:this.src='../../../../static/image/default.png';this.onerror = null" :src="image.url + '-suolue.png'" :data-img="image.url + '.png'" />
              </div>
            </div>
          </div>
        </div>
      </div>
      <OperationLogs2 :orderid="id" :srguid="whinapply.srguid" :departid="whinapply.departid"></OperationLogs2>

    </div>
  </div>
</template>

<script>
  import CommonChart from "../CommonChart";
  import OperationLogs2 from '../../common/OperationLogs2'

  export default {
    name: 'ViewPickingList',
    components: {CommonChart},
    data () {
      return {
        openid: localStorage.openid,//'oIuV2v77MaLCAQILhjI6h6oTWpHI',
        userid: localStorage.userid,//'oIuV2v77MaLCAQILhjI6h6oTWpHI',
        id: '',
        picking: {},
        scraps: [],
        scrapweight: 0,
        whinforms: '',
        whinformweight: 0,
        failedwhs: [],
        failedweight: 0,
        maters: [],
        materweight: 0,
        outforms: [],
        outweight: 0,
        whinapply:{},
        item:[],
        qaform:{},
        qaFormImg:[],
        whiFormImg:[]

      }
    },
    components: {
      OperationLogs2
    },
    created() {
      window.addEventListener('setItem', ()=> {
        this.openid = localStorage.getItem('openid');
        this.userid = localStorage.getItem('userid');
      })
    },
    mounted () {

      this.id = this.$route.query.id;
      this.getWhinapply(this.id);

      //图片浏览器
      $('.weui-panel').on('click', '.uploaderFiles .attachimg', function () {
        var num = $(this).parent().children().not( ".exp" ).length;
        var imgArr = [];
        for (var i=0; i<num; i++) {
          imgArr.push($(this).parent().find('.attachimg').eq(i).data('img'));
        }
        var pnum = $(this).parent().find('.exp').length;
        var index = pnum > 0 ? $(this).index() - pnum : $(this).index();
        var pb = $.photoBrowser({
          items: imgArr,
          initIndex: index
        });
        pb.open();
      });

    },
    methods: {
      getWhinapply: function (id) {
        this.axios({
          method: 'get',
          url: '/produce/Whinapply!getDetails.action',
          params: {guid: id}
        }).then(response => {


          if (response.data.status == 'success') {
            let data = response.data;
            console.log(data.info);
            this.whinapply=data.apply;
            if(data.qaForm != null ){
              this.qaform = data.qaForm;
            }
            if(data.qaFormImg != null ){
              this.qaFormImg = data.qaFormImg;
            }
            if(data.whiFormImg != null ){
              this.whiFormImg = data.whiFormImg;
            }

          } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
            //不不设置提示
          } else {
            this.toastError('系统错误');
          }
        });
      },
      delqaform: function (guid) {
        let that = this;
        var object = Object;
        $.confirm("确定删除!", function() {
          that.axios({
            method: 'post',
            url: '/produce/Whinapply!delQaform.action',
            params: {guid: guid}
          }).then((response) => {
            if (response.data.info == 'success') {

              that.$refs['qaform'].remove();
              that.$refs['qaformTitle'].remove();

              this.toastSuccess('删除成功！');

            } else {
              this.toastError("系统错误");
            }
          })
        }, function() {
          //点击取消后的回调函数
        });
      },


    }
  }
</script>
